package cn.ghx.xboot.store;

import cn.ghx.xboot.common.Result;
import cn.ghx.xboot.common.dto.IdNameDto;
import cn.ghx.xboot.props.Props;
import cn.ghx.xboot.props.PropsService;
import cn.ghx.xboot.setting.Setting;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/store")
public class StoreController {

    public static final String POST = "";
    public static final String GET_LIST = "/list";
    public static final String GET_ALL_NAME = "/name";
    public static final String DELETE = "/{id}";
    public static final String GET_BY_ID = "/{id}";

    private final StoreService service;

    public StoreController(StoreService service) {
        this.service = service;
    }

    @GetMapping(GET_BY_ID)
    public Result<Store> getById(@PathVariable String id){
        return Result.success(service.findById(id));
    }

    @GetMapping(GET_ALL_NAME)
    public Result<List<IdNameDto>> getAllName(@RequestParam(required = false) String adcode){
        return Result.success(service.getAllName(adcode));
    }
 @DeleteMapping(DELETE)
    public Result<Boolean> delete(@PathVariable String id){
        return Result.success(service.deleteById(id));
    }

    @PostMapping(POST)
    public Result<Boolean> save(@RequestBody Store item){
        return Result.success(service.saveItem(item));
    }

    @GetMapping(GET_LIST)
    public Result<Page<Store>> getList(
            @RequestParam(required = false) String keyword ,
            @RequestParam(required = false) String adcode ,
            @RequestParam(required = false,defaultValue = "1") Integer page ,
            @RequestParam(required = false,defaultValue = "10") Integer size){
        return Result.success(service.query(keyword,adcode,page,size));
    }
}
